﻿#pragma once

#include "pch.h"

struct FSubmeshGeometry
{
    UINT IndexCount = 0;
    UINT StartIndexLocation = 0;
    INT BaseVertexLocation = 0;

    DirectX::BoundingBox Bounds;
};

struct FMeshGeometry
{
    std::string Name;

    Microsoft::WRL::ComPtr<ID3DBlob> VertexBufferCPU = nullptr;
    Microsoft::WRL::ComPtr<ID3DBlob> IndexBufferCPU = nullptr;

    Microsoft::WRL::ComPtr<ID3D12Resource> VertexBufferGPU = nullptr;
    Microsoft::WRL::ComPtr<ID3D12Resource> IndexBufferGPU = nullptr;

    Microsoft::WRL::ComPtr<ID3D12Resource> VertexBufferUploader = nullptr;
    Microsoft::WRL::ComPtr<ID3D12Resource> IndexBufferUploader = nullptr;

    // 与缓冲区相关的数据
    UINT VertexByteStride = 0;
    UINT VertexBufferByteSize = 0;
    UINT IndexBufferByteSize = 0;
    DXGI_FORMAT IndexFormat = DXGI_FORMAT_R16_UINT;

    // 一个MeshGeometry结构体能够存储一组顶点/索引缓冲区中的多个几何体
    std::unordered_map<std::string, FSubmeshGeometry> DrawArgs;

    D3D12_VERTEX_BUFFER_VIEW GetVertexBufferView() const;

    D3D12_INDEX_BUFFER_VIEW GetIndexBufferView() const;

    // 待数据上传至GPU后，我们就能释放这些内存了
    void DisposeUploaders();
};
